package br.com.comdoc.engine;

//@author Keanujorge
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;

public class Engine {

    public static void darFocoJComponent(final JDialog parent, final JComponent comp) {

        parent.addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            comp.grabFocus();
                            comp.requestFocus();
                        }
                    });
                }
            }
        });

    }
}
